package jwww.handlers;

import java.io.*;
import java.util.Date;

import jwww.service.Page;
import jwww.util.TextReader;

public class TextFile
extends Page
{
  String data;
  String tmpname;
  String filename;
  String error = null;

  public TextFile(int status, Date date,
                  String tmpname, String filename)
  {
    super(status, date);
    this.tmpname  = tmpname;
    this.filename = filename;
  }

  public boolean read()
  {
    File file = new File(tmpname);

    try
    {
      data = TextReader.read(file);
    }
    catch (IOException e)
    {
      e.printStackTrace();
      error = "Could not serve file.";
      return false;
    }
    return true;
  }

  public void stream(OutputStream output)
    throws IOException
  {
//    int size     = data.length;
//    int p        = 0;
//    int maxchunk = 64*1024;
//    while (p < size)
//    {
//      int chunk  = Math.min(maxchunk, size-p);
//      output.write(data, p, chunk);
//      p += chunk;
//    }
//    // File file = new File(filename);
//    // file.delete();
  }
}
